<?php
namespace App\Controller\Admin;

use App\Model\ProductMenu;
use App\Query\ProductMenuQuery;
use App\Request\ProductMenuRequest;

class ProductMenuController extends Controller
{
    // 列表
    public function index()
    {
        return ProductMenuQuery::model()->get();
    }
    
    // 新增
    public function create(ProductMenuRequest $request)
    {
        if((new ProductMenu)->fill($request->validated())->save())
        {
            $this->message('create');
        }
        
        $this->error('create');
    }
    
    // 更新
    public function update($id, ProductMenuRequest $request)
    {
        $model = ProductMenu::find($id);

        if($model && $model->fill($request->validated())->save())
        {
            $this->message('update');
        }
        
        $this->error('update');
    }
    
    // 删除
    public function delete($id)
    {
        $model = ProductMenu::find($id);
        
        if($model && $model->delete())
        {
            $this->message('delete');
        }

        $this->error('delete');
    }
}